package com.lunar.controller;

import com.lunar.entity.R;
import com.lunar.entity.UserInfo;
import com.lunar.service.UserInfoService;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/login")
public class UserInfoController {
    @Autowired
    UserInfoService userInfoService;

    @RequestMapping("/index")
    public List<UserInfo> getAll(){
        return userInfoService.getAllUser();
    }

    @PostMapping("/login")
    public R login(@Param("aname")String aname,@Param("apassword") String apassword){
        int count = userInfoService.login(aname,apassword);
        if (count>=1){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @PostMapping("/register")
    public R register(UserInfo userInfo){
        int count = userInfoService.register(userInfo);
        if (count>=1){
            return R.ok();
        }else {
            return R.error();
        }
    }
}
